<%@page import="com.hrms.pojo.Employee"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%String path = request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加薪资</title>
<script type="text/javascript" src="<%=path%>/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
	function getEmpName() {
		var id=$("#selectId").val();
		if(id==null||id==0||id==""){
			return;
		}
		$.ajax({
			url:"<%=path %>/pay/getEmName",
			type:"GET",
			data:{emid:id},
			success:function(data){
				$(".empName").val(data);
			}
		});
	}
	function checkformat(){
		var date=$("#date").val();
		var reg=/^\d{4}-\d{1,2}-\d{1,2}/;
		if($.trim(date)==""||reg.test(date)===false){
			alert("请输入合法的年月");
			return false;
		}
		var selectId=$("#selectId").val();
		if($.trim(selectId)==""){
			alert("员工号不能为空");
			return false;
		}
		var payReg=/^\d+(.\d+)?$/;
		var payBase=$("#payBase").val();
		if($.trim(payBase)!=""&&payReg.test(payBase)===false){
			alert("基本工资格式不对");
			return false;
		}
		var payOverTime=$("#payOverTime").val();
		if($.trim(payOverTime)!=""&&payReg.test(payOverTime)===false){
			alert("加班工资格式不对");
			return false;
		}
		var payAge=$("#payAge").val();
		if($.trim(payAge)!=""&&payReg.test(payAge)===false){
			alert("工龄格式不对");
			return false;
		}
		var payCheck=$("#payCheck").val();
		if($.trim(payCheck)!=""&&payReg.test(payCheck)===false){
			alert("考勤费格式不对");
			return false;
		}
		var payAbsent=$("#payAbsent").val();
		if($.trim(payAbsent)!=""&&payReg.test(payAbsent)===false){
			alert("旷工费格式不对");
			return false;
		}
		var paySafety=$("#paySafety").val();
		if($.trim(paySafety)!=""&&payReg.test(paySafety)===false){
			alert("保险费格式不对");
			return false;
		}
	}
</script>
</head>
<body>
	<form action="<%=path %>/pay/addaPay" onsubmit="return checkformat()" method="post">
		<table style="margin: 0 auto;">
			<tr>
				<td>员工号</td>
				<td>
					<select name="empId" id="selectId" onclick="getEmpName()">
						<%
						List<Employee>allEmp=(List<Employee>)request.getAttribute("empList");
						for(Employee employee:allEmp){
						%>
						<option value="<%=employee.getEmId()%>"><%=employee.getEmId()+"   "+employee.getEmName() %></option>
						<%
						}
						%>
					</select>
				</td>
			</tr>
			<tr>
				<td>员工姓名</td>
				<td><input type="text" name="empName" class="empName" value="<%=allEmp.get(0).getEmName()%>"></td>
			</tr>
			<tr>
				<td>发放日期</td>
				<td><input id="date" type="text" name="date">格式：yyyy-MM-dd</td>
			</tr>
			<tr>
				<td>基本工资</td>
				<td><input type="text" name="payBase" id="payBase"></td>
			</tr>
			<tr>
				<td>加班费</td>
				<td><input type="text" name="payOverTime" id="payOverTime"></td>
			</tr>
			<tr>
				<td>工龄</td>
				<td><input type="text" name="payAge" id="payAge"></td>
			</tr>
			<tr>
				<td>考勤费</td>
				<td><input type="text" name="payCheck" id="payCheck"></td>
			</tr>	
			<tr>
				<td>旷工费</td>
				<td><input type="text" name="payAbsent" id="payAbsent"></td>
			</tr>
			<tr>
				<td>保险费</td>
				<td><input type="text" name="paySafety" id="paySafety"></td>
			</tr>
			<tr style="text-align: center;">
				<td><input type="submit" value="提交"></td>
				<td><input type="reset" value="清空"></td>
			</tr>
		</table>	
	</form>
	<div style="margin:50px auto;width: 300px;">
		<h1><a href="<%=path%>/admin/function">返回功能页面</a></h1>
		<h1><a href="<%=path %>/pay/payList">返回薪资列表</a></h1>
	</div>
</body>
</html>